package message

import (
	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/message"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/rpc"
	"github.com/zeromicro/go-zero/core/logc"

	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type NoticeMessageAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 新增公告消息
func NewNoticeMessageAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NoticeMessageAddLogic {
	return &NoticeMessageAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *NoticeMessageAddLogic) NoticeMessageAdd(req *types.AddNoticeMessageReq) (resp *types.Empty, err error) {

	if req.Type != 0 && req.Type != 1 {
		return nil, code.ParamsInvalid
	}

	u, err := l.svcCtx.SettingService.Message.NoticeMessageAdd(l.ctx, &message.AddNoticeMessageReq{
		MerchantId: 1,                          // 商户ID
		Type:       req.Type,                   // 消息类型,0:弹窗消息,1:滚动消息
		Title:      req.Title,                  // 标题
		Content:    req.Content,                // 内容
		Status:     rpc.StatusType(req.Status), // 状态,0:禁用,1:启用
	})

	if err != nil {
		logc.Error(l.ctx, "NoticeMessageAdd err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}

	resp = &types.Empty{}
	return
}
